package com.situ.crm.controller;

import com.situ.crm.pojo.entity.Permission;
import com.situ.crm.pojo.vo.LayUISelectMVO;
import com.situ.crm.service.IPermissionService;
import com.situ.crm.util.JSONResult;
import com.situ.crm.util.LayUITableResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RequestMapping("/permission")
@Controller
public class PermissionController {
	@Autowired
	private IPermissionService permissionService;

	@ApiIgnore
	@RequestMapping("/getPermissionPage")
	public String getPermissionPage() {
		return "/permission/permission_list";
	}


	@RequestMapping("/list")
	@ResponseBody
	public LayUITableResult list(Integer page, Integer limit, Permission permission) {
		return permissionService.list(page, limit, permission);
	}

	@RequestMapping("/deleteById")
	@ResponseBody
	public JSONResult deleteById(Integer id) {
		permissionService.deleteById(id);
		return JSONResult.ok("删除成功");
	}

	@RequestMapping("/deleteAll")
	@ResponseBody
	public JSONResult deleteAll(String ids) {
		permissionService.deleteAll(ids);
		return JSONResult.ok("删除成功");
	}

	@RequestMapping("/getInsertPage")
	public String getInsertPage() {
		return "/permission/permission_insert";
	}

	@RequestMapping("/insert")
	@ResponseBody
	public JSONResult insert(Permission permission) {
		permissionService.insert(permission);
		return JSONResult.ok("添加成功");
	}


	@RequestMapping("/selectAllPermisssions")
	@ResponseBody
	public JSONResult selectAllPermisssions() {
		List<LayUISelectMVO> list = permissionService.selectAllPermisssions();
		return JSONResult.ok(list);
	}
}
